﻿using INTEX.DataBase.Tools;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Windows;
using System.Windows.Data;
using System.Data.OracleClient;
using ReflectionStudio.Components.UserControls;
using System.ComponentModel;
namespace WPFExcelReport
{
    public partial class UIABKOPF : ViewBase
    { 
        public UIABKOPF()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VABKOPF();
            DataContext = MV;
            MESSAGES += "RELOADABK;";
         }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (DesignerProperties.GetIsInDesignMode(this))
                    return;
                if (IsLoaded)
                    return;
                base.Window_Loaded(sender, e);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwABK = dwMaster; 
            if(dwMaster==null)
            {
                KEY = "";
            }
            else
            {
                KEY = TMV.ABKAUFKRS + TMV.ABKAUFLFD;
            }
        }
        #region====WorkFlow========
        public override void OnWorkflowIDChange(MessageEventArgs e)
        {
            base.OnWorkflowIDChange(e);
            MessageInfo msg = e.Info;
            string task = msg.MSGTYPE;
            switch (task)
            {
                case "RELOADABK":
                    ORDERNUM = msg.ORDER;
                    break;
            }
        }
        #endregion
        public override void LOADBYAUF()
        {
            base.LOADBYAUF();
            TBMain.Clear();
            if (ORDERNUM == null)
                return;
            if (ORDERNUM.Length < 8)
                return;
            dwData = TBMain.NewRow();
            dwData["ABKMANDANT"] = app.Mandant;
            dwData["ABKAUFKRS"] = ORDERNUM.Substring(0, 2);
            dwData["ABKAUFLFD"] = ORDERNUM.Substring(2, 6);
            SResult = TMV.QABK01(dwData);
            MergeData(SResult, true, true);
        }
    }
    public partial class UIABKOPF
    {
        public VABKOPF TMV
        {
            get
            {
                return (VABKOPF)MV;
            }
        }
        

        #region ==AUFART===========
        public static readonly DependencyProperty AUFARTProperty = DependencyProperty.Register("AUFART",
            typeof(string), typeof(UIABKOPF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnAUFARTChanged));
        public string AUFART
        {
            get
            {
                return (string)GetValue(AUFARTProperty);
            }
            set
            {
                SetValue(AUFARTProperty, value);
            }
        }
        private static void OnAUFARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIABKOPF;
            if (src != null)
            {
                src.AUFART = (string)e.NewValue;
            }
        }
        #endregion

        #region ==KDAUFTNR===========
        public static readonly DependencyProperty KDAUFTNRProperty = DependencyProperty.Register("KDAUFTNR",
            typeof(string), typeof(UIABKOPF),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnKDAUFTNRChanged));
        public string KDAUFTNR
        {
            get
            {
                return (string)GetValue(KDAUFTNRProperty);
            }
            set
            {
                SetValue(KDAUFTNRProperty, value);
            }
        }
        private static void OnKDAUFTNRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIABKOPF;
            if (src != null)
            {
                src.KDAUFTNR = (string)e.NewValue;
            }
        }
        #endregion

        #region ==dwABK===========
        public static readonly DependencyProperty dwABKProperty = DependencyProperty.Register("dwABK",
            typeof(DataRow), typeof(UIABKOPF),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OdwABKChanged));
        public DataRow dwABK
        {
            get
            {
                return (DataRow)GetValue(dwABKProperty);
            }
            set
            {
                SetValue(dwABKProperty, value);
                OnABKChg();
            }
        }
        private static void OdwABKChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIABKOPF;
            if (src != null)
            {
                DataRow row = (DataRow)e.NewValue;
                src.dwABK = row;
            }
        }
        #endregion
        public virtual  void OnABKChg()
        { }
     

    }
}

